/**
 * 
 */
package fhq.hcmute.modernshopping.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import fhq.hcmute.modernshopping.R;

/**
 * @author: Hien Nguyen Le
 * @emai: hien.nguyenle.it@gmail.com
 * 
 */
public class ProductCommentAdapter extends ArrayAdapter<Comment> {
	private Context context;
	private ArrayList<Comment> comments;

	public ProductCommentAdapter(Context context, ArrayList<Comment> comments) {
		super(context, R.layout.lv_item_product_comment, comments);
		this.context = context;
		this.comments = comments;
	}

	private static class ViewHolder {
		protected TextView txt_CommentId;
		protected TextView txt_Comment;
		protected TextView txt_CommentByTime;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View rowView = convertView;
		if (rowView == null) {
			LayoutInflater inflater = LayoutInflater.from(context);
			rowView = inflater.inflate(R.layout.lv_item_product_comment, null);
			ViewHolder viewHolder = new ViewHolder();
			viewHolder.txt_CommentId = (TextView) rowView
					.findViewById(R.id.txt_comment_id);
			viewHolder.txt_Comment = (TextView) rowView
					.findViewById(R.id.txt_comment);
			viewHolder.txt_CommentByTime = (TextView) rowView
					.findViewById(R.id.txt_comment_by_time);
			rowView.setTag(viewHolder);
		}
		ViewHolder holder = (ViewHolder) rowView.getTag();
		Comment comment = comments.get(position);
		holder.txt_CommentId.setText(position + 1 + "");
		holder.txt_Comment.setText(comment.getUserComment());
		holder.txt_CommentByTime.setText(comment.getUserName() + " - "
				+ comment.getTime());
		return rowView;
	}
}
